#include "ContextGL.h"
#include "egl/egl.h"
#include "../infLib/infLib.h"

bool ContextGL::TestEGLError(char* pszLocation)
{
    /*
    eglGetError returns the last error that has happened using egl,
    not the status of the last called function. The user has to
    check after every single egl call or at least once every frame.
    */
    EGLint iErr = eglGetError();
    if (iErr != EGL_SUCCESS)
    {
        inf::printf("%s failed (%d).\n", pszLocation, iErr);
        return false;
    }

    return true;
}

void ContextGL::MakeCurrent() {
    eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
    TestEGLError("eglMakeCurrent");
}

void ContextGL::PresentContext()
{
    eglSwapBuffers(eglDisplay, eglSurface);
}